#include <stdio.h>

using namespace std;

void Record(int *pData, unsigned int length, bool (*function) (int))
{
    if (pData == NULL || length == 0) {
        return;
    }
    
    int *pBegin = pData;
    int *pEnd = pData + length - 1;
    
    while (pBegin < pEnd) {
        while (pBegin < pEnd && !function(*pBegin)) {
            pBegin ++;
        }
        
        while (pBegin < pEnd && function(*pEnd)) {
            pEnd --;
        }
        
        if (pBegin < pEnd) {
            int temp = *pBegin;
            *pBegin = *pEnd;
            *pEnd = temp;
        }
    }
}

bool isEven(int n)
{
    return (n & 1) == 0;
}

void RecordOddEven(int *pData, unsigned int length)
{
    Record(pData, length, isEven);
}

int main(int argc, const char * argv[]) {
    int pData[7] = {7, 2, 4, 8, 10, 6, 9};
    RecordOddEven(pData, 7);
    for (int i = 0; i < 7; i++) {
        printf("%d\n", *(pData + i));
    }
    return 0;
}
